<?php

namespace app\admin\model;

use think\Model;


class ClientsNeed extends Model
{

    

    

    // 表名
    protected $name = 'clients_need';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'house_status_text',
        'now_status_text',
        'status_text',
        'time_text'
    ];
    

    
    public function getHouseStatusList()
    {
        return ['1' => __('House_status 1'), '2' => __('House_status 2'), '3' => __('House_status 3'), '5' => __('House_status 5')];
    }


    public function getNowStatusList()
    {
        return ['1' => __('Now_status 1'), '2' => __('Now_status 2'), '3' => __('Now_status 3')];
    }

    public function getStatusList()
    {
        return ['1' => __('Status 1'), '2' => __('Status 2')];
    }


    public function getHouseStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['house_status']) ? $data['house_status'] : '');
        $list = $this->getHouseStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getNowStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['now_status']) ? $data['now_status'] : '');
        $list = $this->getNowStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['time']) ? $data['time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


    public function clients()
    {
        return $this->belongsTo('Clients', 'clients_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function tag()
    {
        return $this->belongsTo('Tag', 'tag_ids', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function goods()
    {
        return $this->belongsTo('Goods', 'goods_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
